<template>
  <div class="safety">
    <van-nav-bar
      title="安全中心"
      left-text="返回"
      :fixed="true"
      left-arrow
      @click-left="back"
    ></van-nav-bar>

    <div class="content">
      <van-cell title="修改密码" @click="toChangePassword" is-link />
      <van-cell title="注销账号" @click="logout" is-link />
    </div>
  </div>
</template>

<script>
export default {
  name: "Safety",
  data() {
    return {};
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    toLogin() {
      this.$router.push({name:"Login"});
    },
    toChangePassword() {
      this.$router.push({name:"ChangePassword"});
    },
    logout() {
      this.$dialog
        .confirm({
          title: "你确定要将账号注销吗",
        })
        .then(() => {
          this.axios({
            method: "post",
            url: "/destroyAccount",
          }).then((result) => {

            if (result.data.code == 700) {
              this.$dialog
                .confirm({
                  title: "你尚未登录",
                  message: "请先登录后再试",
                })
                .then(() => {
                  return this.$router.push({ name: "Login" });
                })
                .catch(() => {});
            }
            if(result.data.code == 'G001'){
                this.$notify({ type: "success", message:'账号已注销'});
                setTimeout(()=>{
                    this.$router.push({name:'My'})
                },3000)
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="less" scoped>
.safety {
  padding-top: 76px;
  .van-nav-bar--fixed{
    padding-top: 30px;
    background-color: #0022ab;
  }
  /deep/.van-nav-bar__title{
    color: #fff;
  }
  /deep/.van-icon{
    color: #fff;
  }
  /deep/.van-nav-bar__text{
    color: #fff;
  }
}
</style>